package com.yangmf.auto_message_handle.pojo.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * OSS存储信息封装类
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class StorageInfo {
    private long fileCount;
    private long totalSize;

    /**
     * 获取总大小的友好显示格式
     */
    public String getFormattedSize() {
        if (totalSize < 1024) {
            return totalSize + " B";
        } else if (totalSize < 1024 * 1024) {
            return String.format("%.2f KB", totalSize / 1024.0);
        } else if (totalSize < 1024 * 1024 * 1024) {
            return String.format("%.2f MB", totalSize / (1024.0 * 1024.0));
        } else {
            return String.format("%.2f GB", totalSize / (1024.0 * 1024.0 * 1024.0));
        }
    }

    /**
     * 判断是否包含有效数据
     */
    public boolean isValid() {
        return fileCount >= 0 && totalSize >= 0;
    }
}